package com.wang.springbootinit.sparkAi;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.wang.springbootinit.common.ErrorCode;
import com.wang.springbootinit.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * AI分析
 */
@Service
@Slf4j
public class AnalyseServiceImpl implements AnalyseService{

    @Resource AiAnalyseHandler analyseHandler;

    /**
     * 同步分析
     * @param analyseQueryParam
     * @return
     */
    @Override
    public AiAnalyseModel syncChat(AiAnalyseQueryParam analyseQueryParam) {
        log.info("AnalyseServiceImpl syncChat analyseQueryParam:{}", JSONUtil.toJsonStr(analyseQueryParam));
        if(ObjectUtil.isNull(analyseQueryParam) || ObjectUtil.isNull(analyseQueryParam.getUserQuestionContent())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, ErrorCode.SYSTEM_ERROR.getMessage());
        }
        AiAnalyseModel aiAnalyseModel = analyseHandler.syncChat(analyseQueryParam);
        log.info("AnalyseServiceImpl syncChat aiAnalyseModel:{}", JSONUtil.toJsonStr(aiAnalyseModel));
        return aiAnalyseModel;

    }

    /**
     * 简单问答
     * @param analyseQueryParam
     * @return
     */
    @Override
    public AiAnalyseModel simpleAnswerQuestion(AiAnalyseQueryParam analyseQueryParam) {
        analyseQueryParam.setSystemContent(null);
        log.info("AnalyseServiceImpl simpleAnswerQuestion analyseQueryParam:{}", JSONUtil.toJsonStr(analyseQueryParam));
        if(ObjectUtil.isNull(analyseQueryParam) || ObjectUtil.isNull(analyseQueryParam.getUserQuestionContent())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, ErrorCode.SYSTEM_ERROR.getMessage());
        }
        AiAnalyseModel aiAnalyseModel = analyseHandler.simpleChat(analyseQueryParam);
        log.info("AnalyseServiceImpl simpleAnswerQuestion aiAnalyseModel:{}", JSONUtil.toJsonStr(aiAnalyseModel));
        return aiAnalyseModel;
    }
}
